var a = getApp();

Page({
    data: {
        logo: "",
        name: "",
        intro: "",
        address: "",
        priceDesc: "",
        teamId: "",
        needUpdate: !0
    },
    loadData: function() {
        var t = this;
        a.network.post({
            url: a.url.teamInfo,
            params: {
                id: t.data.teamId
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                1 == e.data.result ? (t.showTeamData(e.data.data.teamInfo), wx.setStorageSync(a.storage.teamInfo, e.data.data.teamInfo)) : a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取团队信息失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    clickName: function(a) {
        wx.navigateTo({
            url: "../teamInfoEdit/teamInfoEdit?type=0"
        });
    },
    clickPhone: function(a) {
        wx.navigateTo({
            url: "../teamInfoEdit/teamInfoEdit?type=1"
        });
    },
    clickArea: function(a) {
        wx.navigateTo({
            url: "../teamInfoEdit/teamInfoEdit?type=2"
        });
    },
    clickSummary: function(a) {
        wx.navigateTo({
            url: "../teamInfoEdit/teamInfoEdit?type=3"
        });
    },
    clickPrice: function(a) {
        wx.navigateTo({
            url: "../teamInfoEdit/teamInfoEdit?type=4"
        });
    },
    clickAvatar: function(a) {
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var t = a.tempFilePaths[0];
                wx.redirectTo({
                    url: "upload/upload?src=" + t
                });
            }
        });
    },
    uploadAvatar: function(t) {
        var e = this;
        a.network.uploadFile({
            url: a.url.editTeamInfo,
            filePath: t,
            name: "img",
            formData: {
                id: e.data.teamId
            },
            before: function() {
                e.setData({
                    uploading: !0,
                    progress: 0
                }), wx.showLoading({
                    title: "提交数据"
                });
            },
            success: function(t) {
                a.util.showToast(t.message), 1 == t.result && e.loadData();
            },
            fail: function() {
                a.util.showToast("提交数据失败");
            },
            complete: function() {
                e.setData({
                    uploading: !1,
                    progress: 0
                }), wx.hideLoading();
            }
        });
    },
    onLoad: function(t) {
        var e = wx.getStorageSync(a.storage.meInfo);
        this.setData({
            teamId: e.teamId
        });
        var o = t.avatar;
        o && (this.uploadAvatar(o), this.setData({
            src: o
        }));
        var n = wx.getStorageSync(a.storage.teamInfo);
        this.showTeamData(n);
    },
    showTeamData: function(a) {
        this.setData({
            priceDesc: a.priceDesc,
            intro: a.intro,
            address: a.address,
            phone: a.phone,
            name: a.name,
            logo: a.logo
        });
    },
    onReady: function() {},
    onShow: function() {
        this.data.needUpdate && (this.loadData(), this.setData({
            needUpdate: !1
        }));
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});